package StudyCode.summary.myfile;

import java.util.Arrays;

/**
 * 版权所有 科技与人文(www.tah1986.com)
 */
public class ByteToHex {
	private final static char[] hexArray = "0123456789ABCDEF".toCharArray();

	public static void main(String[] argv) {
		byte someByte = 2;
		System.out.println("字节 2 转为 16进制:");
		System.out.println(Arrays.toString(byteToHex(someByte)));
	}

	private static char[] byteToHex(byte someByte) {
		char[] hexChars = new char[2];
		int v = someByte & 0xFF;
		hexChars[0] = hexArray[v >>> 4];
		hexChars[1] = hexArray[v & 0x0F];
		return hexChars;
	}
}
